package com.yxjx.duoxue.datamodel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.datamodel.course.DMCourse;
import com.yxjx.duoxue.network.NwUtils;
import com.yxjx.duoxue.utils.UIHelper;

public class DMOrder extends DMObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4578401338318217244L;
	
	private DMProduct product;
	private String orderId = "";
	private ResponseObject orderRspCode = new ResponseObject(-1, "");
	
    // 联系人姓名
    private String contactName;
    // 联系人电话
    private String contactPhone;
    
    // 备注说明(预留)
    private String remark;
    // 订单ID
    private String id = "";
    // 订单类型
    private Integer orderType = -1;
    // 商品id
    private Integer productId = -1;
    // 商品名称
    private String productName = "";
    // 商品数量(预留)
    private Integer productCount = -1;
    // 商品原价
    private Integer costPrice = -1;
    // 折扣价
    private Integer discountPrice = -1;
    // 是否本人（预留）
    private Integer isOwn = -1;
    // 上客人姓名（预留）
    private String toClassUsername = "";
    // 兑换码
    private String idCode = "";
    private Long createTime;
    private Long updateTime;

    // 订单状态
    private Integer orderStatus = -1;
    // 订单状态描述
    private String orderStatusDes = "";

    // 课程信息
    private DMCourse course;// TODO
    
    // 使用的优惠劵列表 "couponList"
    private ArrayList<DMCoupon> usedCoupons = new ArrayList<DMCoupon>();
    // 订单总价
    private int totalPrice = 0;
    // 实际支付宝支付的额度
    private int payPrice = 0;
    
    
    public static DMOrder from(String str) {
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
    	
    	DMOrder order = new DMOrder();
    	try {
			JSONObject jo = new JSONObject(str);
			order = new DMOrder();
		    // 联系人姓名
		    order.setContactName(castString(jo, "contactName"));
		    // 联系人电话
		    order.setContactPhone(castString(jo, "contactPhone"));
		    // 备注说明(预留)
		    order.setRemark(castString(jo, "remark"));
		    // 订单ID
		    order.setId(castString(jo, "id"));
		    // 订单类型
		    order.setOrderType(castInteger(jo, "orderType"));
		    // 商品id
		    order.setProductId(castInteger(jo,"productId"));
		    // 商品名称
		    order.setProductName(castString(jo, "productName"));
		    // 商品数量(预留)
		    order.setProductCount(castInteger(jo, "productCount"));
		    // 商品原价
		    order.setCostPrice(castInteger(jo, "costPrice"));
		    // 折扣价
		    order.setDiscountPrice(castInteger(jo,"discountPrice"));
		    // 是否本人（预留）
		    order.setIsOwn(castInteger(jo,"isOwn"));
		    // 上客人姓名（预留）
		    order.setToClassUsername(castString(jo,"toClassUsername"));
		    order.setCreateTime(castLong(jo,"createTime"));
		    order.setUpdateTime(castLong(jo,"updateTime"));
		    // 订单状态
		    order.setOrderStatus(castInteger(jo,"orderStatus"));
		    // 订单状态描述
		    order.setOrderStatusDes(castString(jo,"orderStatusDes"));
		    // 兑换码
		    order.setIdCode(castString(jo,"idCode"));
		    // 订单价格和实际支付价格
		    order.setTotalPrice(castInteger(jo,"totalPrice"));
		    order.setPayPrice(castInteger(jo,"payPrice"));
		    
		    DMCourse course = new DMCourse();
			NwUtils.fillDataToCourse(jo, course);
			order.setCourse(course);
		    
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	
    	return order;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getProductId() {
        return productId;
    }

    public void setProductId(Integer productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public Integer getProductCount() {
        return productCount;
    }

    public void setProductCount(Integer productCount) {
        this.productCount = productCount;
    }

    public Integer getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(Integer costPrice) {
        this.costPrice = costPrice;
    }

    public Integer getDiscountPrice() {
        return discountPrice;
    }

    public void setDiscountPrice(Integer discountPrice) {
        this.discountPrice = discountPrice;
    }

    public Integer getIsOwn() {
        return isOwn;
    }

    public void setIsOwn(Integer isOwn) {
        this.isOwn = isOwn;
    }

    public String getToClassUsername() {
        return toClassUsername;
    }

    public void setToClassUsername(String toClassUsername) {
        this.toClassUsername = toClassUsername;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    public DMCourse getCourse() {
        return course;
    }

    public void setCourse(DMCourse course) {
        this.course = course;
    }

    public String getOrderStatusDes() {
        return orderStatusDes;
    }

    public void setOrderStatusDes(String orderStatusDes) {
        this.orderStatusDes = orderStatusDes;
    }

    @Override
    public String toString() {
        return "{\"id\":\"" + id + "\", \"orderType\":\"" + orderType + "\", \"productId\":\"" + productId + "\", \"productName\":\"" + productName
                + "\", \"productCount\":\"" + productCount + "\", \"costPrice\":\"" + costPrice + "\", \"discountPrice\":\"" + discountPrice + "\", \"isOwn\":\"" + isOwn
                + "\", \"toClassUsername\":\"" + toClassUsername + "\", \"contactName\":\"" + contactName + "\", \"contactPhone\":\"" + contactPhone
                + "\", \"remark\":\"" + remark + "\", \"createTime\":\"" + createTime + "\", \"updateTime\":\"" + updateTime + "\", \"orderStatus\":\"" + orderStatus
                + "\", \"orderStatusDes\":\"" + orderStatusDes + "\"}";
    }
    
	public DMProduct getProduct() {
		return product;
	}
	public void setProduct(DMProduct product) {
		this.product = product;
	}
	public String getOrderId() {
		return orderId;
	}
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	public ResponseObject getRspCode() {
		return orderRspCode;
	}
	public void setOrderRspCode(ResponseObject orderRspCode) {
		this.orderRspCode = orderRspCode;
	}

	public String getIdCode() {
		return idCode;
	}

	public void setIdCode(String idCode) {
		this.idCode = idCode;
	}

	public int getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(int totalPrice) {
		this.totalPrice = totalPrice;
	}

	public int getPayPrice() {
		return payPrice;
	}

	public void setPayPrice(int payPrice) {
		this.payPrice = payPrice;
	}

}
